package net.keebook.webapp.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;

import net.keebook.webapp.util.SettingId;


@Entity
public class Setting implements Serializable {
	private static final long serialVersionUID = -8718931317830414725L;

	@Enumerated(EnumType.STRING) @Id
	private SettingId id;
	private String value;
	
	public Setting() {
		super();
	}
	
	public Setting(SettingId id, String value) {
		super();
		setId(id);
		setValue(value);
	}
	
	public Setting(SettingId id, Boolean value) {
		this(id, "");
		setValue(value);
	}
	
	public Setting(SettingId id, Long value) {
		this(id, "");
		setValue(value);
	}
	
	public SettingId getId() {
		return id;
	}
	public void setId(SettingId id) {
		this.id = id;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	public void setValue(Boolean value) {
		setValue(value ? "1" : "0");
	}
	public void setValue(Long value) {
		setValue(value.toString());
	}
	
	public String getValue() {
		return value;
	}
	public Boolean getBoolean() {
		return "1".equals(getValue()) ? true : false;
	}
	public Long getLong() {
		return new Long(getValue());
	}
	@Override
	public boolean equals(Object o) {
		if (o instanceof Setting) {
			if (((Setting) o).getId().equals(this.getId())) {
				return true;
			}
		}
		return false;
	}
}
